package com.googlecode.androidkurskoblenz.threedcube;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.PhysicalEnvironment;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;

class CameraView
{
	protected static final PhysicalBody physBody = new PhysicalBody();
	protected static final PhysicalEnvironment physEnv =
			new PhysicalEnvironment();
	protected Canvas3D canvas = null;
	protected BranchGroup rootBG = null;
	protected View view = null;
	protected ViewPlatform viewPlatform = null;
	protected TransformGroup vpTG = null;
	
	public CameraView()
	{
		GraphicsConfigTemplate3D gconfigTempl = new GraphicsConfigTemplate3D();
		GraphicsConfiguration gconfig =
				GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(gconfigTempl);
		canvas = new Canvas3D(gconfig);
		view = new View();
		viewPlatform = new ViewPlatform();
		view.setPhysicalBody(physBody);
		view.setPhysicalEnvironment(physEnv);
		view.attachViewPlatform(viewPlatform);
		view.addCanvas3D(canvas);
		vpTG = new TransformGroup();
		vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		vpTG.addChild(viewPlatform);
		rootBG = new BranchGroup();
		rootBG.setCapability(BranchGroup.ALLOW_DETACH);
		rootBG.addChild(vpTG);
	}
	
	public Canvas3D getCanvas3D()
	{
		return this.canvas;
	}
	
	public BranchGroup getRootBG()
	{
		return this.rootBG;
	}
	
	public View getView()
	{
		return this.view;
	}
	
	public TransformGroup getViewPlatformTransformGroup()
	{
		return this.vpTG;
	}
}
